let sqlQuery = require("./mysql/mysql");//自定义query方法
let express = require("express")
let app = express()
var port = ('3000');
app.set('port', port);
//跨域？？
const cors = require('cors')
app.use(cors({
  origin: ['http://localhost:8848'], //前端地址
  methods: ['GET', 'POST'],
  alloweHeaders: ['Conten-Type', 'Authorization'],
  Credentials:['true']
}))


// 1.注册解析 表单数据的 body-parser
const bodyParser = require('body-parser')
// 处理post请求的中间件
app.use(bodyParser.urlencoded({extended:false}))
// 处理json格式的参数的中间件
app.use(bodyParser.json())


// 2.导入路由模块,app使用其模块
//2.1登录
let login_router = require("./routes/login")
app.use("/login",login_router)
//2.2人物信息
let person_router = require("./routes/person");
app.use("/person",person_router)
// //2.3聊天socket
let chat_router = require("./routes/chat")
app.use("/chat",chat_router)

var http = require('http');
// 套接字模块
//创建HTTP server
var server = http.createServer(app);
// 导入socket.js的封装方法
var socket = require("./routes/socketio")
socket.getSocket(server)

//此处变成http listen
server.listen(port);
// app.listen(3000,()=>{console.log("服务器启动……")})
// 导出
module.exports = app;